home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: What is wrong in this code?
- Date: 14 Jan 1996 04:41:53 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4da1ih$9ml@news.iag.net>
- References: <DL2z7o.2K5@scisun.sci.ccny.cuny.edu>
- NNTP-Posting-Host: pm3-orl4.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <DL2z7o.2K5@scisun.sci.ccny.cuny.edu>, sergio@sci.ccny.cuny.edu
- says...
- >
- >Hello Fellows,
- >
- > I am traying to be literate in C and here is a
- >problem wich I have been unable to detect:
- >
- >#include <stdio.h>
- >#include <math.h>
- >main()
- >{
- >double x;
- >
- >printf("\n Enter a number \n");
- >
- >scanf("%f", &x);
- >
- >printf("\n %e to the power %e is equal to ", x , x );
- >
- >x = pow(x,x);
- >
- >printf(" %12.6f \n", x );
- >
- >}
-
- You are telling scanf to read and store a float, then you procede to pass
- it the address of a double... and you are surprised by unexpected results?
-
- There is a good explanation fo this in the c.l.c faq (Frequently Asked
- Question <in fact I saw this one answered just a day or two ago :-)>) list.
- It is available for anonymous ftp from rtfm.mit.edu /pub/usenet/comp.lang.c.
-
- Basically, scanf requires "%lf" for double and "%Lf" for long double.
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-